package com.study.java.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
* @Name: DateConverterUtils
* @Description: 日期-字符串转换工具类
* @Author: XXX
* @CreateDate: XXX
* @Version: V1.0
 */
public class DateConverterUtils {
	
	private static final String FORMAT = "yyyy-MM-dd" ;
	private static SimpleDateFormat sdf = null ;
	
	static {
		sdf = new SimpleDateFormat(FORMAT) ;
	}
	
	/**
	* @Name: parse
	* @Description: 将给定的字符串转换成日期类型
	* @Author: XXX
	* @Version: V1.0
	* @CreateDate: XXX
	* @Parameters: @param str
	* @Return: Date
	 */
	public static Date parse(String str) {
		Date date = null ;
		try {
			date = sdf.parse(str) ;
		} catch (Exception e) {
			throw new RuntimeException(e) ;
		}
		return date ;
	}
	
	public static String format(Date date) {
		String result = null ;
		try {
			result = sdf.format(date) ;
		} catch (Exception e) {
			throw new RuntimeException(e) ;
		}
		return result ;
	}

}














